﻿using HML.Design;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace HML
{
    /// <summary>
    /// ImageSlide导航栏
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public class ImageSlideNavigationBar
    {
        #region 属性

        private ImageSlideNavigationBarVisibility visible = ImageSlideNavigationBarVisibility.Always;
        /// <summary>
        ///导航栏按钮显示方式
        /// </summary>
        [Description("导航栏按钮显示方式")]
        [PropertyOrder(-200)]
        [DefaultValue(ImageSlideNavigationBarVisibility.Always)]
        public ImageSlideNavigationBarVisibility Visible
        {
            get { return this.visible; }
            set
            {
                if (this.visible == value)
                    return;

                this.visible = value;
                this.CurrentVisible = (this.Visible == ImageSlideNavigationBarVisibility.Always);

                this.InitializeInvalidate();
            }
        }

        private Size size = new Size(25, 50);
        /// <summary>
        /// 按钮Size
        /// </summary>
        [Description("按钮Size")]
        [PropertyOrder(-198)]
        [DefaultValue(typeof(Size), "25, 50")]
        public Size Size
        {
            get { return this.size; }
            set
            {
                if (value.Width < 1)
                {
                    value.Width = 1;
                }
                if (value.Height < 1)
                {
                    value.Height = 1;
                }
                if (this.size == value)
                    return;

                this.size = value;
                this.InitializeInvalidate();

            }
        }

        private int lineThickness = 2;
        /// <summary>
        /// 按钮线条厚度
        /// </summary>
        [Description("按钮线条厚度")]
        [PropertyOrder(-196)]
        [DefaultValue(2)]
        public int LineThickness
        {
            get { return this.lineThickness; }
            set
            {
                if (this.lineThickness == value || value <= 0)
                    return;

                this.lineThickness = value;
                this.InitializeInvalidate();
            }
        }

        private Color borderColor = Color.FromArgb(120, 128, 128, 128);
        /// <summary>
        /// 边框颜色
        /// </summary>
        [Description("边框颜色")]
        [PropertyOrder(-195)]
        [DefaultValue(typeof(Color), "120, 128, 128, 128")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color BorderColor
        {
            get { return this.borderColor; }
            set
            {
                if (this.borderColor == value)
                    return;

                this.borderColor = value;
                this.Invalidate();
            }
        }

        private Color backNormalColor = Color.FromArgb(100, 128, 128, 128);
        /// <summary>
        ///导航栏按钮背景颜色（正常）
        /// </summary>
        [Description("导航栏按钮背景颜色（正常）")]
        [PropertyOrder(-194)]
        [DefaultValue(typeof(Color), "100, 128, 128, 128")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color BackNormalColor
        {
            get { return this.backNormalColor; }
            set
            {
                if (this.backNormalColor == value)
                    return;

                this.backNormalColor = value;
                this.Invalidate();
            }
        }

        private Color lineNormalColor = Color.FromArgb(200, 255, 255, 255);
        /// <summary>
        ///导航栏按钮线条颜色（正常）
        /// </summary>
        [Description("导航栏按钮线条颜色（正常）")]
        [PropertyOrder(-192)]
        [DefaultValue(typeof(Color), "200, 255, 255, 255")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color LineNormalColor
        {
            get { return this.lineNormalColor; }
            set
            {
                if (this.lineNormalColor == value)
                    return;

                this.lineNormalColor = value;
                this.Invalidate();
            }
        }

        private Color backEnterColor = Color.FromArgb(200, 128, 128, 128);
        /// <summary>
        ///导航栏按钮背景颜色（鼠标进入）
        /// </summary>
        [Description("导航栏按钮背景颜色（正常）")]
        [PropertyOrder(-190)]
        [DefaultValue(typeof(Color), "200, 128, 128, 128")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color BackEnterColor
        {
            get { return this.backEnterColor; }
            set
            {
                if (this.backEnterColor == value)
                    return;

                this.backEnterColor = value;
                this.Invalidate();
            }
        }

        private Color lineEnterColor = Color.FromArgb(200, 255, 255, 255);
        /// <summary>
        ///导航栏按钮线条颜色（鼠标进入）
        /// </summary>
        [Description("导航栏按钮线条颜色（鼠标进入）")]
        [PropertyOrder(-188)]
        [DefaultValue(typeof(Color), "200, 255, 255, 255")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color LineEnterColor
        {
            get { return this.lineEnterColor; }
            set
            {
                if (this.lineEnterColor == value)
                    return;

                this.lineEnterColor = value;
                this.Invalidate();
            }
        }

        #region 临时存储

        /// <summary>
        /// 导航栏当前显示状态
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal bool CurrentVisible { get; set; }

        private object prevButton_Object = new object();
        /// <summary>
        /// 上一个按钮对象
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal object PrevButton_Object { get { return this.prevButton_Object; } }

        /// <summary>
        /// 上一个按钮rectf
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal RectangleF PrevButton_Rectangle { get; set; }

        /// <summary>
        /// 上一个按钮线条点集合
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal PointF[] PrevButton_LinePoint { get; set; }

        /// <summary>
        /// 鼠标是否已进入上一个按钮
        /// </summary>
        [DefaultValue(false)]
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal bool PrevButton_MouseEnter { get; set; }

        private object nextButton_Object = new object();
        /// <summary>
        /// 下一个按钮对象
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal object NextButton_Object { get { return this.nextButton_Object; } }

        /// <summary>
        /// 下一个按钮rectf
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal RectangleF NextButton_Rectangle { get; set; }

        /// <summary>
        /// 下一个按钮线条点集合
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal PointF[] NextButton_LinePoint { get; set; }

        /// <summary>
        /// 鼠标是否已进入下一个按钮
        /// </summary>
        [DefaultValue(false)]
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        internal bool NextButton_MouseEnter { get; set; }

        #endregion

        #endregion

        #region 字段

        private ImageSlide owner = null;

        #endregion

        public ImageSlideNavigationBar(ImageSlide owner)
        {
            this.owner = owner;
        }

        #region 私有方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        private void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新计算导航栏并刷新控件
        /// </summary>
        private void InitializeInvalidate()
        {
            if (this.owner != null)
            {
                this.owner.InitializeNavigationBarRectangle();
                this.owner.Invalidate();
            }
        }

        #endregion
    }

}
